home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C14 / Inherit.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  789 b   |  37 lines

  1. //: C14:Inherit.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Simple inheritance
  7. #include "Useful.h"
  8. #include <iostream>
  9. using namespace std;
  10.  
  11. class Y : public X {
  12.   int i; // Different from X's i
  13. public:
  14.   Y() { i = 0; }
  15.   int change() {
  16.     i = permute(); // Different name call
  17.     return i;
  18.   }
  19.   void set(int ii) {
  20.     i = ii;
  21.     X::set(ii); // Same-name function call
  22.   }
  23. };
  24.  
  25. int main() {
  26.   cout << "sizeof(X) = " << sizeof(X) << endl;
  27.   cout << "sizeof(Y) = "
  28.        << sizeof(Y) << endl;
  29.   Y D;
  30.   D.change();
  31.   // X function interface comes through:
  32.   D.read();
  33.   D.permute();
  34.   // Redefined functions hide base versions:
  35.   D.set(12);
  36. } ///:~
  37.